package com.example.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.example.dao.UserDAO;
import com.example.entity.UserDO;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.jws.WebService;
import java.util.List;

/**
 * @Create by Intellij IDEA
 * @Author: songXuSheng
 * @Date: 2021/9/9 14:23
 */
@Service("userService")
@Component
@WebService(targetNamespace = "http://service.example.com/",endpointInterface = "com.example.service.UserService")
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDAO userDao;

    @Override
    public String findById(String id) {
        UserDO userDO = userDao.selectById(id);
        return JSON.toJSONString(userDO);
    }

    @Override
    public Integer addUserDO(String user) {
        UserDO userDO = JSON.parseObject(user.toString(), UserDO.class);
        return userDao.insert(userDO);
    }

    @Override
    public String listUser(Long current, Long limit) {
        Page<UserDO> page=new Page<>(current,limit);
        Page<UserDO> userDOPage = userDao.selectPage(page, null);
        return JSON.toJSONString(userDOPage);
    }

    @Override
    public Integer delete(String id) {

        return userDao.deleteById(id);
    }

    @Override
    public Integer update(String user) {
        UserDO userDO = JSON.parseObject(user.toString(), UserDO.class);
        return userDao.updateById(userDO);
    }

}
